package widgetcommon

import (
	"clientDemo/service/widget_data"
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/driver/desktop"
)

var IsEditMode bool //是否是设计模式

// TouchCallback 鼠标toutch事件 返回值true 表示向下穿透,false 不穿透
//
//	event 当前鼠标在当前控件的位置
//		event.Position 相对坐标：当前控件的相对位置
//		event.AbsolutePosition 绝对坐标：世界坐标
//	pos：当前鼠标相对于上层控件的位置
//	obj: 当前控件对象
//	isContainer：是否是纯容器
type TouchCallback func(event *desktop.MouseEvent, pos fyne.Position, obj IWidgetItem, isContainer bool) bool

type IWidgetItem interface {
	SetName(name string)
	GetName() string
	IsContainer() bool
	SetParent(parent IWidgetItem)
	GetParent() IWidgetItem
	MinSize() fyne.Size
	// GetUserInfo 获得节点的自定义数据
	GetUserInfo() IUserInfo

	SetMinSize(size fyne.Size)
	GetBaseSize() fyne.Size
	Refresh()

	ForEach(cb func(objects IWidgetItem) bool)

	//addWidget(obj fyne.CanvasObject, pos fyne.Position)
	//AddObjects(objects fyne.CanvasObject)

	// AddWidgetContainer 包含AddWidget和SetPosition
	AddWidgetContainer(objects IWidgetItem, pos fyne.Position)
	AddWidgetChild(objects IWidgetItem, pos fyne.Position)
	AddWidgetChildObj(objects IWidgetItem)
	SetPosition(objects fyne.CanvasObject, pos fyne.Position)
	Move2(pos fyne.Position)
	// 事件回调

	SetTouchBeganCallback(cb TouchCallback)
	SetTouchMovedCallback(ccb TouchCallback)
	SetTouchEndedCallback(cb TouchCallback)

	// SetProperty 设置
	SetProperty(key, value string, isProperty bool)
	SetAttribute(key, value string) //skin 属性
}

// IEmptyWidgetEvent 事件透传
type IEmptyWidgetEvent interface {
	MouseDown(ev *desktop.MouseEvent)
	MouseUp(ev *desktop.MouseEvent)
	MouseMoved(ev *desktop.MouseEvent)
}

type IEmptyWidgetTransEvent interface {
	TransMouseDown(ev *desktop.MouseEvent, pos fyne.Position, obj IWidgetItem)
	TransMouseUp(ev *desktop.MouseEvent, pos fyne.Position, obj IWidgetItem)
	TransMouseMoved(ev *desktop.MouseEvent, pos fyne.Position, obj IWidgetItem)
}

// IUserInfo 节点数据
type IUserInfo interface {
	GetName() string
	GetSkinTempName() string
	GetBaseWidgetName() string
	SetProperty(key, value string, isProperty bool)
	SetAttribute(key, value string)
	ForEachProperty(cb func(key, value string))
}

// IWidgetInfo Scene数据
type IWidgetInfo interface {
	GetSkinTempName() string
	SetProperty(key, value string)
}
type ISkinInfo interface {
	GetSkinName() string
	ForEachChild(f func(skinInfo ISkinInfo))
}

// IWidgetSkin skin模板数据
type IWidgetSkin interface {
	GetSkinName() string
	GetBaseWidgetName() string
	ForEachChild(f func(skinInfo ISkinInfo))

	GetAttribute() []*widget_data.Property
	SetAttribute(key, value string)
	//GetProperty() map[string]string
	//SetProperty(key, value string)

	AddProperty(key, value string)
	GetAllProperty() []*widget_data.Property
}

//
//type IWidgetItem interface {
//	MinSize() fyne.Size
//	GetName() string
//	IsContainer() bool
//	GetParent() IWidgetItem
//	// GetUserInfo 获得节点的自定义数据
//	GetUserInfo() common.IUserInfo
//}

//type IWidgetItemProperty interface {
//	SetProperty(key, value string)
//	SetAttribute(key, value string)
//}

type IWidgetFun interface {
	//WidgeTextureInfo paseTextureInfo(std::string strCurrentPath, std::string kValue);
	//cocos2d::Sprite* createSprite(const WidgeTextureInfo& kInfo);
	//cocos2d::SpriteFrame* getFrame( const std::string& kFileName );
	//cocos2d::Sprite* createSprite(const char * kFileName );
	//cocos2d::MenuItemImage* createMenu(std::string normalImage,std::string selectedImage,std::string disabledImage);
	//void setTexture(cocos2d::Sprite* pSprite,const WidgeTextureInfo& kInfo);
	//cocos2d::Node* getChildWidget(cocos2d::Node* pNode,std::string kName);
	//cocos2d::Node* getChildWidgetByName(cocos2d::Node* pNode,std::string kName);
	//cocos2d::Node* getChildWidgetSkin(cocos2d::Node* pNode,std::string kScencName,std::string kSkinName);
	//WidgetUserInfo* getUserInfo(cocos2d::Node* pNode);
	//void setWidgetUserInfo(cocos2d::Node* pNode,std::string kName,std::string kKey,std::string kValue);
	//void setWidgetUserInfo(cocos2d::Node* pNode,std::string kKey,std::string kValue);
	//std::string getUserInfoValue(WidgetUserInfo* pUserInfo,std::string kKey);
	//std::string getWidgetUserInfo(cocos2d::Node* pNode,std::string kName,std::string kKey);
	//std::string getWidgetUserInfo(cocos2d::Node* pNode,std::string kKey);
	//void setWidgetProperty(std::string strKey,cocos2d::Node* pNode,std::string kKey,std::string kValue);
	//void setWidgetProperty(std::string strKey,cocos2d::Node* pNode,std::string kName,std::string kKey,std::string kValue);
	//
	//void setPos(cocos2d::Node* pNode,cocos2d::Vec2 kPoint);
	//void setPos(cocos2d::Node* pNode,std::string kName,cocos2d::Vec2 kPoint);
	//cocos2d::Vec2 getPos(cocos2d::Node* pNode,std::string kName);
}
